package com.manda.smart.hub.common.slf4j;

import cn.hutool.core.util.ServiceLoaderUtil;
import org.slf4j.LoggerFactory;
import org.slf4j.helpers.Reporter;
import org.slf4j.spi.SLF4JServiceProvider;

/**
 * @author hongda.li
 */
public final class Slf4jManager {
    private Slf4jManager() {
    }

    /**
     * 不存在其它实现 SLF4J 规范的日志框架时，加载日志模块
     */
    public static void loadLoggerProviderIfNotSlf4jImpl() {
        if (ServiceLoaderUtil.loadFirstAvailable(SLF4JServiceProvider.class) == null) {
            System.setProperty(Reporter.SLF4J_INTERNAL_VERBOSITY_KEY, LoggerLevel.WARN.name());
            System.setProperty(LoggerFactory.PROVIDER_PROPERTY_KEY, ServiceProvider.class.getName());
        }
    }
}
